package com.app.controller;

import com.app.common.BaseVo;
import com.app.entity.Goods;
import com.app.service.IGoodsService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @autor xiaoyu.fang
 * @date 2019/10/11 17:54
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private IGoodsService IGoodsService;

    @PostMapping("/insert")
    public BaseVo insert(@Validated(Goods.Create.class) @RequestBody Goods goods) {
        IGoodsService.insert(goods);
        return new BaseVo();
    }

    @GetMapping("/detail")
    public BaseVo get(@RequestParam(value = "id") ObjectId id) {
        return new BaseVo(IGoodsService.get(id));
    }

    @GetMapping("/{type}/query-rontline")
    public BaseVo query(@PathVariable(value = "type") Integer type) {
        return new BaseVo(IGoodsService.queryTop3Frontline(type));
    }
}
